// index/pages/ResultTest/ResultTest.js
Page({
  data: {
    totalScore: 0,
    reportLevel: '',
    reportContent: '',
    suggestions: [],
    loading: true,
    reportLevelClass: ''
  },

  onLoad(options) {
    // options.score为传递的总分
    const score = parseInt(options.score, 10) || 0;
    this.setData({ totalScore: score });
    this.generateReport(score);
  },

  generateReport(score) {
    let report = {};
    if (score >= 0 && score <= 30) {
      report = {
        level: "很不健康",
        content: "您的心理状态非常不健康，可能需要及时调整。",
        suggestions: [
          "进行心理咨询",
          "参加放松活动",
          "保持规律作息"
        ]
      };
    } else if (score > 30 && score <= 60) {
      report = {
        level: "比较健康",
        content: "您近期可能有些压力，需要适当放松。",
        suggestions: [
          "听音乐放松",
          "进行户外运动",
          "和朋友聊天"
        ]
      };
    } else if (score > 60 && score <= 90) {
      report = {
        level: "健康",
        content: "您的心理状态良好，继续保持。",
        suggestions: [
          "保持良好的生活习惯",
          "定期进行自我反思",
          "培养兴趣爱好"
        ]
      };
    } else if (score > 90 && score <= 100) {
      report = {
        level: "非常健康",
        content: "您的心理状态极佳，继续保持积极心态。",
        suggestions: [
          "分享快乐给他人",
          "尝试新的挑战",
          "保持学习的热情"
        ]
      };
    }
    this.setData({
      reportLevel: report.level,
      reportContent: report.content,
      suggestions: report.suggestions,
      loading: false,
      reportLevelClass: report.level === "很不健康" ? "level-danger" :
                       report.level === "比较健康" ? "level-warning" :
                       report.level === "健康" ? "level-normal" : "level-success"
    });
  }
});